#include	<sys/socket.h>
#include	<sys/types.h>
#include	<netinet/in.h>
#include	<arpa/inet.h>
#include	<assert.h>
#include	<fcntl.h>

#include	"a_global_vars.h"
//------------------------------------------------------------------------------
int create_udp_server_socket(char ip[STRING_LENGTH], int port)
{
	int sid;
	
	sid = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	
	ring_self_addr.sin_family=AF_INET;
	ring_self_addr.sin_port=htons(port);
	ring_self_addr.sin_addr.s_addr=inet_addr(ip);

	int e = bind(sid, (struct sockaddr*)&ring_self_addr, sizeof(ring_self_addr));
	assert( e!= -1);
	return sid;
}
//------------------------------------------------------------------------------
int create_udp_client_socket(char ip[STRING_LENGTH], int port)
{
	int sid;
	sid = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

	ring_successor_addr.sin_family = AF_INET;
	ring_successor_addr.sin_port = htons(port);
	ring_successor_addr.sin_addr.s_addr = inet_addr(ip);
	
	return sid;
}
//------------------------------------------------------------------------------



